﻿using System;
using System.Collections.Generic;
using System.Linq;
using Risk.Services;

namespace Site.Models
{
    public class ActiveGamesDTO
    {
        public String Username { get; set; }
        public ActiveGamesDTO(string username)
        {
            Username = username;
        }
        public List<GameDTO> Games
        {
            get { return DatabaseManager.GetActiveGameIds(Username).Select(gameId => new GameDTO(gameId)).ToList(); }
        }

        public int PlayerRiskId
        {
            get { return DatabaseManager.GetPlayerRiskId(Username); }
        }

        public string GetPlayerState(PlayerDTO player)
        {
            switch (player.State)
            {
                case 0:
                    return "Waiting";
                case 1:
                    return "Initial";
                case 2:
                    return "Reinforcing";
                case 3:
                    return "Attacking";
                case 4:
                    return "Moving troops";
                default:
                    return "Unknown";
            }
        }

        public string GenerateGameLink(GameDTO game)
        {
            //omdat Html.ActionLink() geen slash toevoegt
            return String.Format("<a href=\"/Game/{0}/{1}/\">Id: {2} Players: {3}</a>", game.Id, PlayerRiskId, game.Id, game.Players.Count); 
        }
    }
}